// ==================================================================================================
// Copyright(C) 2018 FI Ltd. All rights reserved.
//
// SYSTEM NAME	   : FI.Net Application Framework
// COMPONENT ID	   : FI.Helpers.Data.Commands
// COMPONENT DESC  :		
//
// CREATED DATE/BY :	18 Aug 2018 / Tian Mi
//
// REVISION HISTORY:	DATE/BY			SR#/CS/PM#/OTHERS		DESCRIPTION OF CHANGE
// ==================================================================================================

using System;
using System.Data.Common;
using System.Diagnostics.CodeAnalysis;
using FI.Helpers.Data.Properties;

namespace FI.Helpers.Data
{
    /// <summary>
    /// Commands, include Select/Insert/Update/Delete commands for the table.
    /// </summary>
    public class Commands
    {
        internal Commands()
        {}

        /// <summary>
        /// Property of Select command
        /// </summary>
        /// <value>The select command.</value>
        public DbCommand SelectCommand { get; set; }

        /// <summary>
        /// Property of Insert command
        /// </summary>
        /// <value>The insert command.</value>
        public DbCommand InsertCommand { get; set; }

        /// <summary>
        /// Property of Update command
        /// </summary>
        /// <value>The update command.</value>
        public DbCommand UpdateCommand { get; set; }

        /// <summary>
        /// Property of Delete command
        /// </summary>
        /// <value>The delete command.</value>
        public DbCommand DeleteCommand { get; set; }

        /// <summary>
        /// Gets the db command.
        /// </summary>
        /// <param name="dbOperationType">Type of the db operation.</param>
        /// <returns>The <see cref="DbCommand"/> corresponding to the <see cref="DbOperationType"/> specified.</returns>
        public DbCommand GetDbCommand(DbOperationType dbOperationType)
        {
            switch (dbOperationType)
            {
                case DbOperationType.Select:
                    return SelectCommand;
                case DbOperationType.Insert:
                    return InsertCommand;
                case DbOperationType.Update:
                    return UpdateCommand;
                case DbOperationType.Delete:
                    return DeleteCommand;
                default:
                    throw new ArgumentOutOfRangeException(
                            string.Format(Resources.Culture, Resources.ArgumentOutOfRange, "dbOperationType"));
            }
        }
    }
}